<%@ page language="java" %>

<%@ page import="com.scalar.chiptrack.utils.ConfigManager"%>

<%@ taglib uri="/WEB-INF/struts-bean.tld" prefix="bean" %>
<%@ taglib uri="/WEB-INF/struts-html.tld" prefix="html" %>
<%@ taglib uri="/WEB-INF/struts-logic.tld" prefix="logic" %>
<%@ taglib uri="/WEB-INF/struts-nested.tld" prefix="nested" %>
<%@ taglib uri="/WEB-INF/chiptrack-tags.tld" prefix="chiptrack" %>

<chiptrack:checkLogon sourcePage="/testRelease.do" />

<%String chipTracContext = "/" + ConfigManager.getChipTracContext(); %>

<HTML>
<HEAD><TITLE>Scalarsoft - ChipTrac</TITLE>
<META http-equiv=Content-Type content="text/html; charset=windows-1252">
<LINK href="<%=chipTracContext%>/jsp/includes/stylesheets/scalarsoft.css" type="text/css" rel="stylesheet"></HEAD>
<script src="<%=chipTracContext%>/jsp/includes/scripts/functions.js"></script>
<script src="<%=chipTracContext%>/jsp/includes/scripts/validations.js"></script>
<script src="<%=chipTracContext%>/jsp/includes/scripts/assembly_release.js"></script>
<script src="<%=chipTracContext%>/jsp/includes/scripts/quickSearch.js"></script>

<SCRIPT language="JavaScript">
window.onload=init;

function init()
{
    qs_1 = new QuickSearch(document.testReleaseForm['searchFGProcessStepId'], document.testReleaseForm.qs1, false);
}
function searchLotsForNewReleases()
{
    var form = document.testReleaseForm;
    var errors = ""

    if( form.searchFGProcessStepId.value == "-1" )
    {
        errors = errors + "<li>Select Part Number to generate test Release";
    }
    if( form.searchVendorId.value == "-1" )
    {
        errors = errors + "<li>Select Vendor to generate test Release";
    }
    if( form.searchReleaseType.value == "-1" )
    {
        errors = errors + "<li>Select Release Type to generate test Release";
    }
    if ( form.searchFromVendorId.value == "-1")
    {
        errors = errors + "<li>Select from Vendor to generate test Release";
    }
    if( errors != "" )
    {
        var pa=document.getElementById("errors");
        pa.innerHTML = errors;
        return;
    }
    else
    {
        document.testReleaseForm.searchWithCompulsoryFields.value = 'true';
        document.testReleaseForm.action = '<%=chipTracContext%>/testRelease.do?action=searchNew';
        document.testReleaseForm.submit();
    }
}

function createNewTestRelease()
{
    var form                    = document.testReleaseForm;
    var selectedLotsObj         = form.hiddenLot;
    var atleastOneLotSelected   = false;
    var errors                  = "";

    if( typeof( selectedLotsObj.length ) == "undefined" )
    {
        if( form['availableLotsList[0].selected'].checked == true )
        {
            atleastOneLotSelected = true;
        }
    }
    else
    {
        for( var i=0; i < selectedLotsObj.length; i++ )
        {
            if( form['availableLotsList[' + i + '].selected'].checked == true )
            {
                //alert( " LOT NUMBER = " + form['availableLotsList[' + i + '].lotNumber'].value + " :: AVAIL-QTY = " + form['availableLotsList[' + i + '].qtyAvailable'].value )
                atleastOneLotSelected = true;
                break;
            }
        }
    }
    if( atleastOneLotSelected == false )
    {
        errors = "<li>Please select atleast one Lot Number";
    }
    if( errors != "" )
    {
        var pa=document.getElementById("errors");
        pa.innerHTML = errors;
        return;
    }
    else
    {
        document.testReleaseForm.action = '<%=chipTracContext%>/testRelease.do?action=new';
        document.testReleaseForm.submit();
    }
}

function disableSelectedLots()
{
    var form                    = document.testReleaseForm;
    var selectedLotsObj         = form.hiddenLot;
    var atleastOneLotSelected   = false;
    var errors                  = "";

    if( typeof( selectedLotsObj.length ) == "undefined" )
    {
        if( form['availableLotsList[0].removed'].checked == true )
        {
            atleastOneLotSelected = true;
        }
    }
    else
    {
        for( var i=0; i < selectedLotsObj.length; i++ )
        {
            if( form['availableLotsList[' + i + '].removed'].checked == true )
            {
                atleastOneLotSelected = true;
                break;
            }
        }
    }
    if( atleastOneLotSelected == false )
    {
        errors = "<li>Please select aleast on Lot Number to delete";
    }
    if( errors != "" )
    {
        var pa=document.getElementById("errors");
        pa.innerHTML = errors;
        return;
    }
    else
    {
        document.testReleaseForm.removeUnnecessaryLots.value = 'true';
        document.testReleaseForm.searchWithCompulsoryFields.value = 'true';
        document.testReleaseForm.action = '<%=chipTracContext%>/testRelease.do?action=searchNew';
        document.testReleaseForm.submit();
    }
}

function loadTurnKeyLabel()
{
    var form = document.testReleaseForm;
    var errors = ""

    if( errors != "" )
    {
        var pa=document.getElementById("errors");
        pa.innerHTML = errors;
        return;
    }
    else
    {
        resetFabLotsForNewReleasesTable();
        document.testReleaseForm.turnKeySelected.value = 'true';
        document.testReleaseForm.action = '<%=chipTracContext%>/testRelease.do?action=searchNew';
        document.testReleaseForm.submit();
    }
}

function resetFabLotsForNewReleasesTable()
{
    var form            = document.testReleaseForm;
    var selectedLotsObj = form.hiddenLot;
    if( typeof( selectedLotsObj ) != "undefined" )
    {
        var pa = document.getElementById("fabLotsForNewReleasesTable");
        pa.innerHTML = "";
    }
}

function partNumberChanged()
{
    var turnKeyLabel = document.getElementById("turnKeyLabel");
    turnKeyLabel.innerHTML = "";

    document.testReleaseForm.searchTurnKey.checked = false;
}        

function reset()
{
    document.testReleaseForm.reset();
    qs_1.resetQuickSearchCntrl();
}

function showLotHistory( lotNumber )
{
    newWindow = window.open( '<%=chipTracContext%>/lotHistory.do?lotNumber=' + lotNumber,'fabLotHistory','channelmode=no,directories=no,toolbar=no,menubar=no,personalbar=no,status=no,scrollbars=yes,width=650,height=300,left=100,top=50,resizable=yes' );
    newWindow.moveTo( 100, 50 );
    newWindow.focus();
}
function getLotReleaseDetails( lotId )
{
    newWindow = window.open('<%=chipTracContext%>/testRelease.do?action=showReleaseInfo&lotId=' + lotId ,'LotReleaseHistory','channelmode=no,directories=no,toolbar=no,menubar=no,personalbar=no,status=no,scrollbars=yes,width=650,height=300,left=100,top=50,resizable=yes');
    newWindow.moveTo( 100, 50 );
    newWindow.focus();
}
function getTransitLots()
{
    newWindow = window.open ('<%=chipTracContext%>/testRelease.do?action=showTransitLots','transitLotsPopup','channelmode=no,directories=no,toolbar=no,menubar=no,personalbar=no,status=no,scrollbars=yes,width=650,height=500,resizable=yes');
    newWindow.focus();
}
</SCRIPT>

<BODY bgColor="#ffffff" leftMargin="0" topMargin="0" marginheight="0" marginwidth="0">

<!-- Top Header Start-->
<%@ include file="/jsp/includes/header.jsp" %>
<!-- Top Header End-->

<TABLE cellSpacing=0 cellPadding=0 width="100%" border=0>
	<TR>
    	<TD width='180' valign='top' background='<%=chipTracContext%>/jsp/includes/images/left_red_bg.gif'>
            <!-- Side Navigation start -->
            <%@ include file="/jsp/operations/releaseMenu.jsp" %>
            <!-- end of the side navigations -->
        </TD>
        <TD bgcolor="#ffffff"><IMG height=9 src="<%=chipTracContext%>/jsp/includes/images/spacer.gif" width=8></TD>
	    <TD bgcolor="#ffffff"><IMG height=480 src="<%=chipTracContext%>/jsp/includes/images/spacer.gif" width=2></TD>
	    <TD valign="top" width="100%">
            <IMG height=1 src="<%=chipTracContext%>/jsp/includes/images/clear.gif" width=500 border=0>
	        <BR>
        	<html:form action="/testRelease.do" method="POST" type="com.scalar.chiptrack.operations.release.forms.TestReleaseForm" onsubmit="javascript:return false">
    		<TABLE width="100%" align="center" cellpadding="2" cellspacing="2" border="0">
                <TR>
                    <TD width="5%" align="left">&nbsp;</td>
                    <TD colspan='3' width="95%" align="left" cellpadding="2" cellspacing="2">
                        <table border="0" width="100%" align="left">
                            <TR><TD colspan="5" class="NArialW" align="center">Test Release</TD></TR>
                            <TR><TD colspan='5' align="left" class='NArialL'>&nbsp;<FONT id="errors" color='FF0000'></font></TD></TR>
                            <TR><TD colspan='5' class="NArialL"><chiptrack:errors styleClass="NArialL"/></TD></TR>
                            <TR><TD colspan='5' class="NArialL"><chiptrack:info styleClass="NArialL"/></TD></TR>
                            <TR><TD colspan='5'><IMG src="<%=chipTracContext%>/jsp/includes/images/spacer.gif" height='10'></TD></TR>
                            <tr>
                                <td class="NArialL">Quick Search Part No:</td>
                                <td class="NArialL">
                                    <input type="text" name="qs1" class="txfield" size='26' onkeyup='quickSearch(qs_1)'/>
                                </td>
                                <td colspan='3'>&nbsp;</td>
                            </tr>
                            <tr>
                                <td class="NArialL" width="22%">Test Part Number:</td>
                                <td class="NArialL" width="20%">
                                    <%--<html:select property="searchProcessStepId" styleClass="txfield" onchange="javascript:resetFabLotsForNewReleasesTable()" style="width:180px">--%>
                                    <html:select property="searchFGProcessStepId" styleClass="txfield" onchange="javascript:resetFabLotsForNewReleasesTable()" style="width:180px">
                                        <html:option value="-1">--Select Part Number--</html:option>
                                        <html:options collection="partNumberList" property="value" labelProperty="label"/>
                                    </html:select>
                                </td>
                                <td width="5%">&nbsp;</td>
                                <td class="NArialL" width="15%">Test Vendor:</td>
                                <td class="NArialL" width="38%">
                                    <html:select property="searchVendorId" styleClass="txfield" onchange="javascript:resetFabLotsForNewReleasesTable()" style="width:180px">
                                        <html:option value="-1">--Select Vendor--</html:option>
                                        <html:options collection="toVendorList" property="value" labelProperty="label"/>
                                    </html:select>
                                    <input type="hidden" name="searchWithCompulsoryFields" />
                                </td>
                            </tr>
                            <TR><TD colspan='5'><IMG src="<%=chipTracContext%>/jsp/includes/images/spacer.gif" height='5'></TD></TR>
                            <tr>
                                <td class="NArialL">Release Type:</td>
                                <td class="NArialL">
                                    <html:select property="searchReleaseType" styleClass="txfield" onchange="javascript:resetFabLotsForNewReleasesTable()" style="width:180px">
                                        <html:option value="-1">--Select Release Type--</html:option>
                                        <html:options name="releaseTypes"/>
                                    </html:select>
                                </td>
                                <td>&nbsp;</td>
                                <td class="NArialL">After Completion Vendor:</td>
                                <td class="NArialL">
                                    <html:select property="searchShipToVendorId" styleClass="txfield" onchange="javascript:resetFabLotsForNewReleasesTable()" style="width:180px">
                                        <html:option value="-1">--Select Vendor--</html:option>
                                        <html:options collection="shipmentLocationsList" property="value" labelProperty="label"/>
                                    </html:select>
                                </td>
                            </tr>
                            <TR><TD colspan='5'><IMG src="<%=chipTracContext%>/jsp/includes/images/spacer.gif" height='5'></TD></TR>
                            <tr>
                                <td class="NArialL">From Vendor:</td>
                                <td class="NArialL">
                                    <html:select property="searchFromVendorId" styleClass="txfield" onchange="javascript:resetFabLotsForNewReleasesTable()" style="width:180px">
                                        <html:option value="-1">--Select Vendor--</html:option>
                                        <html:options collection="fromVendorList" property="value" labelProperty="label"/>
                                    </html:select>
                                </td>
                                <td>&nbsp;</td>
                                <td class="NArialL"><!--TurnKey:--></td>
                                <td class="NArialL">
                                    <%--<html:checkbox property="searchTurnKey" styleClass="txfield" onclick="javascript:loadTurnKeyLabel();" />
                                    <input type="hidden" name="turnKeySelected" />
                                    <font id="turnKeyLabel">
                                        <bean:write name="testReleaseForm" property="searchTurnKeyLabel" />
                                    </font>--%>
                                </td>
                            </tr>    
                            <TR><TD colspan='5'><IMG src="<%=chipTracContext%>/jsp/includes/images/spacer.gif" height='5'></TD></TR>
                            <tr>
                                <td colspan="5" align="center">
                                    <a href="javascript:searchLotsForNewReleases()" ><img border="0" src="<%=chipTracContext%>/jsp/includes/images/search.gif" width="53" height="17" onmouseover="window.status='Click to Search for Test Release';return true" onmouseout="window.status='';return true"title="Click to Search for Test Release"/></a>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                                    <a href="javascript:reset()"><img border="0" src="<%=chipTracContext%>/jsp/includes/images/reset.gif" width="53" height="17" onmouseover="window.status='Click to Reset';return true" onmouseout="window.status='';return true" title="Click here to Reset"></a>
                                </td>
                            </tr>
                            <TR><TD colspan='5'><IMG src="<%=chipTracContext%>/jsp/includes/images/spacer.gif" height='5'></TD></TR>
                            <TR><td colspan="5" class="NArialL">Please <A href="javascript:getTransitLots()" class="leftsection">Click here</A> to receive the Tranist Lots</td></TR>
                        </table>
                    </TD>
                </TR>
                <jsp:include page="/jsp/operations/test_release_search_new_lot.jsp" flush="true"/>
        </TABLE>
	</html:form>
<!-- till here -->
<BR><BR><BR></TD>
<TD bgcolor="#ffffff"><IMG height=1 src="<%=chipTracContext%>/jsp/includes/images/spacer.gif" width=1></TD>
</TR>
</TABLE>

<!-- Footer starts here -->
<%@ include file="/jsp/includes/footer.jsp" %>
<!-- footer end here -->

</BODY>
</HTML>

<%--
<%}catch(Exception e){ e.printStackTrace(); }%>--%>
